/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spakehelpdesk.bean;

import com.spakehelpdesk.entity.FAQs;
import com.spakehelpdesk.entity.Priority;
import com.spakehelpdesk.java.MessageManage;
import com.spakehelpdesk.java.SessionManage;
import com.spakehelpdesk.java.URLManage;
import com.spakehelpdesk.session.FAQsSession;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author leehoanh
 */
@SessionScoped
public class FAQsBean implements Serializable {

    @EJB
    private FAQsSession fAQsSession;
    private List<FAQs> listFAQs;
    private FAQs selectFAQs;
    private FAQs newFAQs = new FAQs();

    public FAQsSession getfAQsSession() {
        return fAQsSession;
    }

    public void setfAQsSession(FAQsSession fAQsSession) {
        this.fAQsSession = fAQsSession;
    }

    public List<FAQs> getListFAQs() {
        return listFAQs;
    }

    public void setListFAQs(List<FAQs> listFAQs) {
        this.listFAQs = listFAQs;
    }

    public FAQs getNewFAQs() {
        return newFAQs;
    }

    public void setNewFAQs(FAQs newFAQs) {
        this.newFAQs = newFAQs;
    }

    public FAQs getSelectFAQs() {
        return selectFAQs;
    }

    public void setSelectFAQs(FAQs selectFAQs) {
        this.selectFAQs = selectFAQs;
    }

    public List<FAQs> getAll() {
        return fAQsSession.getAll();
    }

    public FAQs getAllByID(int id) {
        return fAQsSession.getFAQsById(id);
    }

    public List<FAQs> getFAQs() {
        if (SessionManage.getValue("loadFAQs") == null) {
            listFAQs = fAQsSession.getAll();
            SessionManage.setValue("loadFAQs", "loaded");
        }
        return listFAQs;
    }
    //navigate to ManageDeprtment page

    public void back() {
        //Check the exist of session loaddepartment
        if (SessionManage.getValue("loadFAQs") != null) {
            SessionManage.remove("loadFAQs");
        }
        URLManage.sendRediret("Admin/ManageFAQs.xhtml");
    }
    //Create d new department

    public void createNew() {

        fAQsSession.createNewFAQs(newFAQs);

        MessageManage.message(FacesMessage.SEVERITY_INFO, "Create successful!", "Successful!");

        newFAQs = new FAQs();
        if (SessionManage.getValue("loadFAQs") != null) {
            SessionManage.remove("loadFAQs");
        }


    }

    //delete FAQs
    public void delete() {
        fAQsSession.remove(selectFAQs);
        if (SessionManage.getValue("loadFAQs") != null) {
            SessionManage.remove("loadFAQs");
        }
    }
    //Update or edit a department

    public void update() {
        selectFAQs = fAQsSession.updateFAQs(selectFAQs);
        if (SessionManage.getValue("loadFAQs") != null) {
            SessionManage.remove("loadFAQs");
        }

    }

    /**
     * Creates a new instance of FAQsBean
     */
    public FAQsBean() {
        
    }
    
    public void toFAQs(){
        URLManage.sendRediret("Employee/ViewFAQs.xhtml");
    }
}
